package bintree.leetcode;

public class Num17_11单词最小距离 {
    public static void main(String[] args) {
        String[] words = {"I","am","a","student","from","a","university","in","a","city"};
        String word1 = "a";
        String word2 = "student";
        System.out.println(findClosest(words,word1,word2));
    }
    public static int findClosest(String[] words, String word1, String word2) {
        int ret = 10000,fir = -1,sec = -1;
        for (int i = 0; i < words.length; i++) {
            if (words[i].equals(word1)){
                fir=i;
            }
            if (words[i].equals(word2)){
                sec = i;
            }
            ret=Math.min(ret,Math.abs(sec-fir));
        }
        return ret;
    }
}
